<?php
class event extends base{

  function __construct()
  {
    parent::__construct();
    $this->m = load('m/event');
  }

  function index()
  {
    $tot = $this->m->count();
    $psize = 30;
    $param['pagination'] = pagination($tot , seg(3) , $psize ,'/event/index/');
    $param['records'] = $this->m->get("", seg(3), $psize);
    $this->display('event/list-table',$param);
  }


  function view($id)
  {
    $param['r'] = $this->m->get($id);
    $this->display('event/show',$param);
  }


  function add()
  {
    $conf = array('title'=>'required','customer'=>'required','linkman'=>'required','creator'=>'required','next'=>'required','start_time'=>'required','estimate_time'=>'required','actual_time'=>'required','description'=>'required','state'=>'required','event_type'=>'required','event_state'=>'required','event_handle'=>'required','remark'=>'required','input_time'=>'required','input_people'=>'required','update_time'=>'required','update_people'=>'required','public'=>'required',);
    
    $err = validate($conf);
    if ( $err === TRUE) {
      $this->m->add();
      redirect('/event/add/','发布成功！');
    }
    else {
      $param['val'] = $_POST; 
      $param['err'] = $err;
      $this->display('event/add',$param);    
    }
  }    

  function edit($id)
  {
    $conf = array('title'=>'required','customer'=>'required','linkman'=>'required','creator'=>'required','next'=>'required','start_time'=>'required','estimate_time'=>'required','actual_time'=>'required','description'=>'required','state'=>'required','event_type'=>'required','event_state'=>'required','event_handle'=>'required','remark'=>'required','input_time'=>'required','input_people'=>'required','update_time'=>'required','update_people'=>'required','public'=>'required',);
    $err = validate($conf);
  	if ( $err === TRUE) {
      $this->m->update($id);
      redirect('/event/','修改成功！');
    }
    else {
      $param['val'] = array_merge($_POST,$this->m->get($id));
      $param['err'] = $err;
      $this->display('event/add',$param);    
    }
  }

  function del($id)
  {
    $this->m->del($id);
    redirect('/event/','删除成功！');
  }
}